#include "bufferutil.h"

namespace b2gdns {

	unsigned short read16bits(char*& buffer)
	{
		unsigned short value = static_cast<unsigned char>(buffer[0]);
		value <<= 8;
		value += static_cast<unsigned char>(buffer[1]);
		buffer += 2;
		return value;
	}

	unsigned int read32bits(char*& buffer)
	{
		unsigned int value = static_cast<unsigned char>(buffer[0]);
		value <<= 8;
		value += static_cast<unsigned char>(buffer[1]);
		value <<= 8;
		value += static_cast<unsigned char>(buffer[2]);
		value <<= 8;
		value += static_cast<unsigned char>(buffer[3]);
		buffer += 4;
		return value;
	}

	void write16bits(char*& buffer, unsigned short bytes)
	{
		buffer[0] = (bytes & 0xff00) >> 8;
		buffer[1] = bytes & 0xff;
		buffer += 2;
	}

} // namespace b2gdns
